﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RentalSystem.Data.EF;

namespace Web.Models
{
    public class MovieViewModel
    {
        public string Guid
        {
            get
            {
                if (Movie != null) return Movie.MovieGuid;
                return "0";
            }
        }
        public string Title
        {
            get
            {
                if (Movie != null) return Movie.MovieTitle;
                return "Unknown";
            }
        }
        public Movies Movie { get; set; }

        //checkbox list (movie kinds)
        public List<MovieKinds> AvailableKinds { get; set; }
        public List<MovieKinds> SelectedKinds { get; set; }
        public PostedKinds PostedKinds { get; set; }

        //statistics
        public int TotalRentsCount
        {
            get
            {
                int count = 0;

                if (Movie != null && Movie.Discs != null)
                {
                    foreach (Discs disc in Movie.Discs)
                    {
                        if (disc.Hires != null) count += disc.Hires.Count;
                    }
                }

                return count;
            }
        }
        public List<Votes> LastVotes
        {
            get
            {
                if (Movie == null || Movie.Votes == null)
                    return null;

                return Movie.Votes.OrderByDescending(x => x.VoteDateTime).Take(10).ToList();
            }
        }

        //comments
        public string NewComment { get; set; }
        public List<Comments> Comments { get; set; }
        public PagingInfo CommentsPagingInfo { get; set; }

    }
    public class PostedKinds
    {
        public string[] KindsIDs { get; set; }
    }
}